package com.example.CarManagement.sys.controller;

import com.example.CarManagement.common.Result;
import com.example.CarManagement.sys.entity.Permission;
import com.example.CarManagement.sys.service.IPermissionService;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 权限表管理 前端控制器
 * </p>
 *
 * @author 徐佳彪
 * @since 2025-07-08
 */

@RestController
@RequestMapping("/sys/permission")
public class PermissionController {

    @Resource
    private IPermissionService permissionService;

    @GetMapping("/list")
    public Result<?> getPermissionList() {

        // 获取权限列表 树结构
        List<Permission> list = permissionService.list();
        // 按照权限等级分组，将相同 level 的权限放入同一个 List 中
        Map<String, List<Permission>> permissionMap = list.stream().collect(Collectors.groupingBy(Permission::getLabel));

        return Result.success(permissionMap);
    }

}
